import api from '../index'
import type { LoginRes } from './types/user'
import type { QueryData } from './types/ent'

export default {
  // 登录
  login: (data: {
    accountCode: string
    password: string
  }) => api<LoginRes>({
    method: 'post',
    url: '/Authorization/AccountLogon',
    data,
  }),

  // 获取权限
  permission: () => api({
    url: 'user/permission',
    baseURL: '/mock/',
  }),
  // 获取账号信息
  GetAccountInfo: () => api<LoginRes>({
    url: '/Authorization/GetAccountInfo',
    method: 'post',
  }),
  // 退出登录
  loginOut: () => api({
    url: '/Authorization/AccountLogout',
    method: 'post',
  }),
  // 账号列表
  GetAccountList: (data: QueryData) => api({
    url: '/Authorization/GetAccountList',
    method: 'post',
    data,
  }),
  // 账号列表
  GetRoleList: () => api<any[]>({
    url: '/Authorization/GetRoleList',
    method: 'post',
  }),
  // 新增账号
  AddAccount: (data: { accountInfo: any }) => api({
    url: '/Authorization/AddAccount',
    method: 'post',
    data,
  }),
  // 修改账号
  UpdateAccount: (data: { accountInfo: any }) => api({
    url: '/Authorization/UpdateAccount',
    method: 'post',
    data,
  }),
  // 删除账号
  DeleteAccount: (data: { accountObjID: string }) => api({
    url: '/Authorization/DeleteAccount',
    method: 'post',
    data,
  }),
  // 重置密码
  ResetAccountPassword: (data: { accountCode: string }) => api({
    url: '/Authorization/ResetAccountPassword',
    method: 'post',
    data,
  }),
  // 获取角色配置
  GetPopedoms: () => api<any>({
    url: '/Authorization/GetPopedoms',
    method: 'post',
  }),
  // 获取角色配置
  GetRolePopedoms: (data: { roleObjID: string }) => api({
    url: '/Authorization/GetRolePopedoms',
    method: 'post',
    data,
  }),
  // 设置角色配置
  SetRolePopedoms: (data: { roleObjID: string, popedoms: any }) => api({
    url: '/Authorization/SetRolePopedoms',
    method: 'post',
    data,
  }),
  // 添加角色
  AddRole: (data: { role: any }) => api({
    url: '/Authorization/AddRole',
    method: 'post',
    data,
  }),
  // 删除角色
  DeleteRole: (data: { roleObjID: string }) => api({
    url: '/Authorization/DeleteRole',
    method: 'post',
    data,
  }),
  // 修改角色
  UpdateRole: (data: { role: any }) => api({
    url: '/Authorization/UpdateRole',
    method: 'post',
    data,
  }),
  // 获取权限
  GetAccountPopedomByProgram: (data: { programCode: string }) => api({
    url: '/Authorization/GetAccountPopedomByProgram',
    method: 'post',
    data,
  }),

  // 修改密码
  UpdatePassword: (data: {
    accountCode: string
    oldPassword: string
    newPassword: string
  }) => api({
    url: '/Authorization/UpdatePassword',
    method: 'post',
    data,
  }),
}
